package org.web.demo.servlet;


import lombok.extern.slf4j.Slf4j;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author yexi
 */
@WebServlet("/include")
@Slf4j
public class IncludeServlet extends HttpServlet {

    public IncludeServlet() {
        log.info("IncludeServlet实例化");
    }

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        log.info("IncludeServlet处理请求");
        RequestDispatcher requestDispatcher = req.getRequestDispatcher("/WEB-INF/views/dispatcher.jsp");
        requestDispatcher.include(req, resp);
        resp.getWriter().println("<h4>使用include转发途径的servlet也可以通过include继续追加内容</h4>");
    }

    @Override
    public void destroy() {
        log.info("IncludeServlet对象销毁");
    }

    @Override
    public void init() throws ServletException {
        log.info("IncludeServlet属性初始化");
    }
}
